import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  OneToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Enterprise } from './enterprise.entity';
import {
  AdministrativePenalty,
  DishonestyRecord,
  Lawsuit,
  MovablePropertyMortgage,
} from '../types/EnterpriseBackgroundTypes';

@Entity({
  name: 'enterprise_background',
})
export class EnterpriseBackground {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToOne(() => Enterprise, { onDelete: 'CASCADE', onUpdate: 'CASCADE' })
  @JoinColumn({ name: 'enterprise_id' })
  enterprise: Enterprise;

  @Column({
    name: 'historical_info',
    type: 'text',
    nullable: true,
  })
  historicalInfo: string;

  @Column({
    name: 'lawsuits',
    type: 'json',
    nullable: true,
  })
  lawsuits: Lawsuit[]; // 法律诉讼（数组）

  @Column({
    name: 'administrative_penalties',
    type: 'json',
    nullable: true,
  })
  administrativePenalties: AdministrativePenalty[]; // 行政处罚（数组）

  @Column({
    name: 'dishonesty_record',
    type: 'json',
    nullable: true,
  })
  dishonestyRecords: DishonestyRecord[]; // 失信记录（数组）

  @Column({
    name: 'movable_property_mortgage',
    type: 'json',
    nullable: true,
  })
  movablePropertyMortgages: MovablePropertyMortgage[]; // 动产抵押（数组）

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
  })
  riskLevel: string;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;
}
